#include "PhysicObject.h"


PhysicObject::PhysicObject( ) :
	m_pObjectRef(0),
	m_isActive(false),
	m_pContactSolver(0),
	m_tType(kPhysicObjectTypeNone)
{

}


PhysicObject::~PhysicObject( )
{
	if( m_pObjectRef ){
		m_pObjectRef->release( );
	}
}



void PhysicObject::initWithObject( CCNode* pObject , PhysicObjectType type )
{
	if( m_pObjectRef )
		m_pObjectRef->release( );

	m_pObjectRef = pObject;
	m_pObjectRef->retain( );

	setType(type);
}


void PhysicObject::checkCollision( PhysicObject* pContact )
{
	CCScene* pCurrScene = CCDirector::sharedDirector()->getRunningScene();
	if( !pCurrScene )
		return;

	CCPoint posBullet = this->getObjectRef()->getParent()->convertToWorldSpace( this->getObjectRef()->getPosition() );
	CCPoint posCircle = pContact->getObjectRef()->getParent()->convertToWorldSpace( pContact->getObjectRef()->getPosition() );

	if( Utility::sharedUtility()->checkCircleVsCircle( posBullet , this->getObjectRef()->boundingBox().size.width / 2 ,
														posCircle , pContact->getObjectRef()->boundingBox().size.width / 2 ) )
	{
		if( m_pContactSolver ){
			m_pContactSolver->beginContact( this , pContact );
		}
	}
}